/* customRef一般和Hooks配合使用 */
import { customRef } from 'vue';

export default function(initValue: string, delay: number) {
    let timer: number;
    let msg = customRef((track, trigger) => {
        return {
            get() {
                track();
                return initValue;
            },
            set(newValue) {
                initValue = newValue;

                clearTimeout(timer);
                timer = setTimeout(() => {
                    trigger();
                }, delay);
            }
        };
    });

    return { msg };
}
